﻿using Mirror;
using UnityEngine;

namespace Code.CharacterSystem
{
    public struct CreateCharacterMessage : NetworkMessage
    {
        public GameObject Character;
        public string Name;
    }
    public class CreateCharacterNetworkManaager : NetworkManager
    {
        [SerializeField]private GameObject _character;
        public override void OnServerAddPlayer(NetworkConnectionToClient conn)
        {
            base.OnServerAddPlayer(conn);
        }

        public override void OnStartServer()
        {
            NetworkServer.RegisterHandler<CreateCharacterMessage>(OnCreateCharacter);
        }

        private void OnCreateCharacter(NetworkConnectionToClient conn, CreateCharacterMessage message)
        {           
            GameObject characterInstance = message.Character;
            NetworkServer.ReplacePlayerForConnection(conn, characterInstance, true);
            //characterInstance.GetComponent<Player>().SetPlayerName(_playerNameText.text);
        }
    }
}
